#include <iostream>
#include <queue>
#include <map>

long long const inf = 1 << 30;
std::map<long long, long long> dis;
long long n, m;

int main()
{
	std::cin >> n >> m;
	dis[n] = 0;
	std::queue<long long> q;
	q.push(n);
	while (!q.empty()) {
		long long now = q.front(); q.pop();
		if (now == m) {
			std::cout << dis[now] << '\n';
			break;
		}
		if (now < m && 2 * now < inf && dis.find(2 * now) == dis.end()) {
			dis[2 * now] = dis[now] + 1;
			q.push(2 * now);
		}
		if (now - 1 > 0 && dis.find(now - 1) == dis.end()) {
			dis[now - 1] = dis[now] + 1;
			q.push(now - 1);
		}
	}
}

